#!/usr/bin/env python
"""
    This file is for demonstrating functionalities of sdbm.py
    Users can read from Naacl and Giza++ corpus from files and
    upload the data to Amazon SimpleDB

    For specific command-line usage of this program, please refer
    to README in the same directory

    Author: Brian, Kai
"""
from sdbm import *

if __name__ == '__main__':
    import sys
    if '../../clir' not in sys.path:
        sys.path.append('../../clir')
    import aligned_sent
    from aligned_parser import GizaReader, NaaclReader
    
    cfg = connect_database('config.cfg')


    from optparse import OptionParser
    usage = "usage: %prog [options]"
    parser = OptionParser(usage=usage)
    parser.add_option('--data-format', action='store', type='string',dest='data_format',
                      help='specify dataset format, could be giza or naacl')
    parser.add_option('-d',  '--directory',  action='store',  type='string',  dest='directory',
                      help='specify directory where dataset is located')
    parser.add_option('-f', '--data-file', action='append', type='string', dest='data_files',
                      help='specify corresponding data files')
    parser.add_option('--lang',  action='store',  type='string',  dest='lang',
                      help='specify dataset language(s)')
    parser.add_option('--author',  action='store', type='string', dest='author',
                      help='specify author information')
    parser.add_option('--copyright',  action='store',  type='string',  dest='copyright',
                      help='specify copyright information')
    parser.add_option('--version',  action='store',  type='string',  dest='version',
                      help='specify version number')
    (options,  args) = parser.parse_args()

    additional_info = dict()
    if not options.author == None:
        additional_info['AUTHOR'] = options.author
    if not options.copyright == None:
        additional_info['COPYRIGHT'] = options.copyright
    if not options.version == None:
        additional_info['REVISION'] = options.version
    if not options.lang == None:
        additional_info['LANG'] = options.lang
    if options.data_format == None or options.data_files == None or \
       options.directory == None or options.lang == None:
        parser.print_help()
        exit(-1)
    
    if options.data_format == 'naacl':
        corpus = NaaclReader(options.directory, options.data_files)
    elif options.data_format == 'giza':
        corpus = GizaReader(options.directory, options.data_files)
    
    create_domain_from_corpus(options.data_format, corpus, additional_info)
